﻿namespace SpLocalizer.Common.DataStructures
{
    public class Tuple<TFirst, TSecond>
    {
        public Tuple(TFirst first, TSecond second)
        {
            First = first;
            Second = second;
        }

        public TFirst First { get; private set; }
        public TSecond Second { get; private set; }

        public override bool Equals(object obj)
        {
            if (!(obj is Tuple<TFirst, TSecond>))
                return false;
            var tuple = (Tuple<TFirst, TSecond>) obj;
            return Equals(First, tuple.First) && Equals(Second, tuple.Second);
        }

        public override int GetHashCode()
        {
            if (First != null)
                return First.GetHashCode();
            if (Second != null)
                return Second.GetHashCode();
            return 0;
        }
    }

    public class Tuple<TFirst, TSecond, TThird> : Tuple<TFirst, TSecond>
    {
        public Tuple(TFirst first, TSecond second, TThird third)
            : base(first, second)
        {
            Third = third;
        }

        public TThird Third { get; private set; }

        public override bool Equals(object obj)
        {
            if (!(obj is Tuple<TFirst, TSecond, TThird>))
                return false;
            var tuple = (Tuple<TFirst, TSecond, TThird>) obj;
            return base.Equals(tuple) && Equals(Third, tuple.Third);
        }

        public override int GetHashCode()
        {
            if (base.GetHashCode() != 0)
                return base.GetHashCode();
            if (Third != null)
                Third.GetHashCode();
            return 0;
        }
    }
}